package com.cqcj.wms.query;

import lombok.Data;

/**
 * 查询结果对象封装
 */
@Data
public class QueryResult {

    private int code;//编码 200/400
    private String msg;//成功/失败 message
    private Long total;//总记录数
    private int pageSize;//每页显示的条数
    private Object data;//数据

    /**
     * 访问失败
     * @return
     */
    public static QueryResult fail(){
        return result(400,"失败",0L,10,null);
    }

    public static QueryResult suc(){
        return result(200,"成功",0L,10,null);
    }
    public static QueryResult fail(String msg){
        return result(400,msg,0L,10,null);
    }
    public static QueryResult suc(Object data){
        return result(200,"成功",0L,10,data);
    }

    public static QueryResult suc(Object data, Long total, int pageSize){
        return result(200,"成功",total,pageSize,data);
    }

    private static QueryResult result(int code, String msg, Long total, int pageSize, Object data){
        QueryResult res = new QueryResult();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setTotal(total);
        res.setPageSize(pageSize);
        return res;
    }

}
